home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / TCP_IP / TNOS230S / RSPFDUMP.C < prev    next >
C/C++ Source or Header  |  1996-08-29  |  3KB  |  133 lines

  1. #include "global.h"
  2. #include "mbuf.h"
  3. #include "netuser.h"
  4. #include "internet.h"
  5. #include "ip.h"
  6. #include "trace.h"
  7. #include "rspf.h"
  8.  
  9. #if !defined(_lint)
  10. static char rcsid[] OPTIONAL = "$Id: rspfdump.c,v 1.9 1996/08/29 12:11:16 root Exp root $";
  11. #endif
  12.  
  13. #ifdef RSPF
  14.  
  15.  
  16. /* Dump an RSPF packet */
  17. void
  18. rspf_dump (fp, bpp, source, dest, check)
  19. FILE *fp;
  20. struct mbuf **bpp;
  21. uint32 source, dest;
  22. int check;            /* If 0, bypass checksum verify */
  23. {
  24. union rspf rspf;
  25. struct pseudo_header ph;
  26. int16 csum;
  27. int sync;
  28.  
  29.     if (bpp == NULLBUFP || *bpp == NULLBUF)
  30.         return;
  31.  
  32.     traceprintf (fp, "RSPF: ");
  33.  
  34.     /* Compute checksum */
  35.     ph.source = source;
  36.     ph.dest = dest;
  37.     ph.protocol = RSPF_PTCL;
  38.     ph.length = len_p (*bpp);
  39.     if ((csum = cksum (&ph, *bpp, ph.length)) == 0)
  40.         check = 0;    /* No checksum error */
  41.  
  42.     (void) ntohrspf (&rspf, bpp);
  43.  
  44.     if (rspf.hdr.version != RSPF_VERSION)
  45.         traceprintf (fp, "version %u ", rspf.hdr.version);
  46.     switch (rspf.hdr.type) {
  47.         case RSPF_FULLPKT:
  48.             if (rspf.pkthdr.csum == 0)
  49.                 check = 0;
  50.             traceprintf (fp, "type ROUTING UPDATE ");
  51.             if (rspf.pkthdr.fragtot != 1)
  52.                 traceprintf (fp, "fragment %u frag total %u ", rspf.pkthdr.fragn,
  53.                          rspf.pkthdr.fragtot);
  54.             if (rspf.pkthdr.sync != 4)
  55.                 traceprintf (fp, "sync %u ", rspf.pkthdr.sync);
  56.             traceprintf (fp, "nodes %u id %u", rspf.pkthdr.nodes, rspf.pkthdr.envid);
  57.             if (check)
  58.                 traceprintf (fp, " CHECKSUM ERROR (%u)", csum);
  59.             traceprintf (fp, "\n");
  60.             if (rspf.pkthdr.sync != 0)
  61.                 sync = rspf.pkthdr.sync - 4;
  62.             else
  63.                 sync = len_p (*bpp);
  64.             if (sync % 5 != 0) {
  65.                 traceprintf (fp, "      %d bytes\n", sync);
  66.                 (void) pullup (bpp, (unsigned char *) 0, (int16) sync);
  67.                 sync = 0;
  68.             }
  69.             rspfnodedump (fp, bpp, sync / 5);
  70.             break;
  71.         case RSPF_RRH:
  72.             if (rspf.rrh.csum == 0)
  73.                 check = 0;
  74.             traceprintf (fp, "type RRH seq 0x%04x flags %d", rspf.rrh.seq, rspf.rrh.flags);
  75.             if (check)
  76.                 traceprintf (fp, " CHECKSUM ERROR (%u)", csum);
  77.             traceprintf (fp, "\n");
  78.             break;
  79.         default:
  80.             traceprintf (fp, "Unknown packet type\n");
  81.     }
  82. }
  83.  
  84.  
  85. void
  86. rspfnodedump (fp, bpp, adjcnt)
  87. FILE *fp;            /* uses tputs() if NULLFILE */
  88. struct mbuf **bpp;        /* routing update without packet header */
  89. int adjcnt;            /* number of links before first node header */
  90. {
  91. int c, links = 0;
  92. char buf[128];
  93. struct rspfnodeh nodeh;
  94. struct rspflinkh linkh;
  95.  
  96.     *buf = '\0';
  97.     for (;;) {
  98.         if (*buf != '\0') {
  99.             if (fp != NULLFILE)
  100.                 traceprintf (fp, "%s", buf);
  101.             else
  102.                 tputs (buf);
  103.             *buf = '\0';
  104.         }
  105.         if (len_p (*bpp) == 0)
  106.             break;
  107.         if (adjcnt) {
  108.             if ((c = PULLCHAR (bpp)) == -1)
  109.                 break;
  110.             sprintf (buf, "            %s/%u\n", inet_ntoa (pull32 (bpp)), c);
  111.             adjcnt--;
  112.             continue;
  113.         }
  114.         if (links) {
  115.             if (ntohrspflink (&linkh, bpp) == -1)
  116.                 break;
  117.             sprintf (buf, "      horizon %u ERP factor %u cost %u adjacencies %u\n",
  118.               linkh.horizon, linkh.erp, linkh.cost, linkh.adjn);
  119.             adjcnt = linkh.adjn;
  120.             links--;
  121.             continue;
  122.         }
  123.         if (ntohrspfnode (&nodeh, bpp) == -1)
  124.             break;
  125.         sprintf (buf, "      Reporting Router: %s Seq %u Subseq %u links %u\n",
  126.             inet_ntoa (nodeh.addr), (int16) nodeh.seq, nodeh.subseq,
  127.              nodeh.links);
  128.         links = nodeh.links;
  129.     }
  130. }
  131.  
  132. #endif /* RSPF */
  133.